package com.funong.matrix.biz.system.domain;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.funong.matrix.biz.base.dao.SysLogDao;
import com.funong.matrix.biz.base.entity.SysLogEntity;
import com.funong.matrix.biz.system.pojo.qo.SysLogQO;
import com.funong.matrix.core.dto.QueryDTO;
import com.funong.matrix.core.dto.Result;
import com.funong.matrix.core.utils.DateTimeUtil;
import com.funong.matrix.core.utils.JwtUtils;
import com.funong.matrix.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author : NaNa
 * @since : 2023-05-19 16:55
 **/
@Slf4j
@Service
public class SysLogDomainDao {
    @Resource
    private SysLogDao logDao;

    public void saveSystemLogInfo(SysLogEntity logEntity) {
        String currentUserName = JwtUtils.getCurrentUserName();
        if(StringUtils.isNotBlank(currentUserName)){
            logEntity.setOperator(currentUserName)
                    .setCreatedBy(currentUserName);
        }
        logEntity.setCreatedAt(DateTimeUtil.now())
                .setUpdatedAt(DateTimeUtil.now());
        logDao.save(logEntity);
    }

    public Result querySysLogByCondition(QueryDTO<SysLogQO> queryDTO) {
        IPage<SysLogEntity> logEntityIPage = logDao.queryLogByCondition(queryDTO);
        return Result.success(logEntityIPage);
    }
}
